//
//  HotPlaceTableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/1/24.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "HotPlaceTableViewCell.h"
#import "SearchResultElement.h"
@implementation HotPlaceTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}

- (void)setModel:(Elements *)model{
    
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    _BackImageView.layer.cornerRadius = 8;
    _BackImageView.layer.masksToBounds = YES;
    _AlphaView.layer.cornerRadius = 8;
    _AlphaView.layer.masksToBounds = YES;
    _PictureImageView.layer.cornerRadius = 20;
    _PictureImageView.layer.masksToBounds = YES;
    
    _LogoView.alpha = 0;
    _LogoView.layer.cornerRadius = 3;
    _LogoView.layer.masksToBounds = YES;
    
    _LogoSvIEW.alpha = 0;
    _LogoSvIEW.layer.cornerRadius = 2;
    _LogoSvIEW.layer.masksToBounds = YES;
    
    if ([_model.type integerValue] == 4 ) {
        _LogoView.alpha = 1;
    }else{
        _LogoSvIEW.alpha = 1;
    }
    
    
    [self setValues];
}

- (void)setModelElement:(SearchResultElement *)modelElement{
    if (_modelElement != modelElement) {
        [_modelElement release];
        _modelElement = [modelElement retain];
    }
    
    _BackImageView.layer.cornerRadius = 8;
    _BackImageView.layer.masksToBounds = YES;
    _AlphaView.layer.cornerRadius = 8;
    _AlphaView.layer.masksToBounds = YES;
    _PictureImageView.layer.cornerRadius = 20;
    _PictureImageView.layer.masksToBounds = YES;
    
    _LogoView.alpha = 0;
    _LogoView.layer.cornerRadius = 3;
    _LogoView.layer.masksToBounds = YES;
    
    _LogoSvIEW.alpha = 0;
    _LogoSvIEW.layer.cornerRadius = 2;
    _LogoSvIEW.layer.masksToBounds = YES;
    
    if ([_model.type integerValue] == 4 ) {
        _LogoView.alpha = 1;
    }else{
        _LogoSvIEW.alpha = 1;
    }
    
    
    
    [_BackImageView sd_setImageWithURL:[NSURL URLWithString:modelElement.cover_image_w640] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    _TitleLabel.text = _modelElement.name;
    
    _LookNumber.text = [NSString stringWithFormat:@"%@", _modelElement.liked_count];
    
}



- (void)setValues{
    
    NSDictionary *dic = _model.data[0];    
    
        [_BackImageView sd_setImageWithURL:[NSURL URLWithString:dic[@"cover_image_1600"]] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
   

    if ([_model.type integerValue] == 4) {
        if (dic[@"name"] == nil) {
            
        }else{
            
            _TitleLabel.text = dic[@"name"];
        }
        
    }
    
    
    
    if ([_model.type integerValue] == 12) {
        if ([dic[@"index_title"] isEqualToString:@""]) {
           
            _TitleLabel.text = dic[@"name"];
        }else{
            
            _TitleLabel.text = dic[@"index_title"];
        }
    }
    
    _TimeLabel.text = dic[@"first_day"];
    
    if ([_model.type integerValue] == 4) {
        _dayOrStory.text = [NSString stringWithFormat:@"%@ 天", dic[@"day_count"]];
    }
    
    
    if ([_model.type integerValue] == 12) {
        _dayOrStory.text = [NSString stringWithFormat:@"%@ 故事", dic[@"spot_count"]];
    }
    
    
    _LookNumber.text = [NSString stringWithFormat:@"%@ 浏览", dic[@"view_count"]];
    
    
    if ([_model.type integerValue] == 4) {
        _PlaceName.text = dic[@"popular_place_str"];
    }
    
    if ([_model.type integerValue] == 12) {
        _PlaceName.text = nil;
    }
    
    [_PictureImageView sd_setImageWithURL:[NSURL URLWithString:dic[@"user"][@"avatar_m"]] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    
    _NameLabel.text = dic[@"user"][@"name"];
    
}


- (void)awakeFromNib {
    // Initialization code
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"yeJianMoShi"] isEqualToString:@"isDay"]) {
        self.backgroundColor = DAYCOLOR;
    }else{
        self.backgroundColor = NIGHTCOLOR;
    }
    
    


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"yeJianMoShi" object:nil];



}

- (void)changeColor:(NSNotification *)notification{
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"yeJianMoShi"]isEqualToString:@"isNight"]) {
        self.backgroundColor = NIGHTCOLOR;
    }else{
        
        self.backgroundColor = DAYCOLOR;
    }
    
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeColor" object:nil];
    [_BackImageView release];
    [_AlphaView release];
    [_LogoView release];
    [_TimeLabel release];
    [_dayOrStory release];
    [_LookNumber release];
    [_PlaceName release];
    [_PictureImageView release];
    [_byLabel release];
    [_NameLabel release];
    [_TitleLabel release];
    [_LogoSvIEW release];
    [super dealloc];
}
@end
